<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 * 客户信息db管理
 */

require_once(dirname(__FILE__) . "/../common/EasyMysql.php");
require_once(dirname(__FILE__) . "/../config/ConfigDB.php");

class ServiceCom{
    
    function __construct()
    {
        $dbconfig = $GLOBALS["config"] ['database'];
        $mysql = new EasyMysql ($dbconfig['hostname'], $dbconfig ['port'], $dbconfig ['username'], $dbconfig ['password'], $dbconfig ['db'], $dbconfig ['charset']);
        $this->mysql = $mysql;
    }
    
    function getServiceById($id){
        try{
            $sql = "select * from service where id={$id}";
            $ret = $this->mysql->query($sql);
            if(!empty ($ret) && !empty ($ret [0]) && !empty ($ret [0][0])){
                return $ret[0][0];
            }
        } catch (Exception $ex) {
            //throw new Exception ("AppDao.fetchList: " . $ex->getMessage());
            return false;
        }
        return false;
    }
    
    function getServicearr(){
        try{
            $sql = "select * from service order by id ASC";
            $ret = $this->mysql->query($sql);
            if(!empty ($ret) && !empty ($ret [0]) && !empty ($ret [0][0])){
                return $ret[0];
            }
        } catch (Exception $ex) {
            //throw new Exception ("AppDao.fetchList: " . $ex->getMessage());
            return false;
        }
        return false;
    }
    
    function getServicelist($minlimit, $limitnum){
        try {
            $sql = "select * from service order by id ASC limit {$minlimit},{$limitnum}";
            $ret = $this->mysql->query($sql);
            if (!empty($ret) && !empty($ret [0]) && !empty($ret [0][0])) {
                return $ret[0];
            }
        } catch (Exception $ex) {
            //throw new Exception ("AppDao.fetchList: " . $ex->getMessage());
            return false;
        }
        return false;
    }
    
    function getAllNum() {
        try {
            $sql = "select count(1) from service";
            $ret = $this->mysql->query($sql);
            if (!empty($ret) && !empty($ret [0]) && !empty($ret [0][0])) {
                return $ret [0][0]['count(1)'];
            }
        } catch (Exception $ex) {
            //throw new Exception ("AppDao.fetchList: " . $ex->getMessage());
            return false;
        }
        return null;
    }
    
    function addService($name,$fee,$countfee,$isncard){
        try {
            $sql = "insert into service(name,fee,countfee,isncard) values('{$name}',{$fee},{$countfee},{$isncard});SELECT @@Identity";
            $ret = $this->mysql->query($sql);
            return $ret[0][0]['@@Identity'];
        } catch (Exception $ex) {
            //throw new Exception ("AppDao.fetchList: " . $ex->getMessage());
            return false;
        }
        return false;
    }
    
    function deleteService($id){
        try {
            $sql = "delete from service where id={$id}";
            $ret = $this->mysql->query($sql);
            return true;
        } catch (Exception $ex) {
            //throw new Exception ("AppDao.fetchList: " . $ex->getMessage());
            return false;
        }
        return false;
    }
    
    function updateService($id,$name,$fee,$countfee){
        try {
            $sql = "update service set name='{$name}',fee={$fee},countfee={$countfee} where id={$id}";
            $ret = $this->mysql->query($sql);
            return true;
        } catch (Exception $ex) {
            //throw new Exception ("AppDao.fetchList: " . $ex->getMessage());
            return false;
        }
        return false;
    }
    
}